using System;
using System.Collections.Generic;

namespace Mercenary
{
    public class StraPveNormal : IStrategy
    {
        public static string m_name = UiItemConst.策略_PVE通用.m_name;
        public static int m_mercMax=6;
        public List<MercCard> m_mercList = new List<MercCard>();

        public string Name() { return m_name; }

        public List<MercCard> GetMercList() { return m_mercList; }

        public (int hand_index, int play_index) GetEnterOrder(
            List<MercCard> hand_mercenaries,
            List<MercCard> play_mercenaries)
        {
            int 鞭笞者特里高雷 = UtilsStra.FindMercenaryIndexForName(
                "鞭笞者特里高雷", play_mercenaries);
            if (鞭笞者特里高雷 == 0)
                return (0, 鞭笞者特里高雷);
            else if (鞭笞者特里高雷 > 0)
                return (0, 鞭笞者特里高雷 + 1);
            return (0, play_mercenaries.Count);
        }

        public void UpdateMercList()
        {
            m_mercList.Clear();
            /*
            List<LettuceMercenary> mercs = CollectionManager.Get().FindOrderedMercenaries(
                null, new bool?(true), null, null, null).m_mercenaries.FindAll(
                    m => !m.IsReadyForCrafting());

            if ((m_mercList.Count+3) <= m_mercMax)
            {
                //火焰队
                var fire = mercs.Find(m => m.m_mercName.Contains(MercConst.安东尼达斯.m_name)) ??
                            mercs.Find(m => m.m_mercName.Contains(MercConst.赤精.m_name)) ??
                            mercs.Find(m => m.m_mercName.Contains(MercConst.巴琳达_斯通赫尔斯.m_name));
                if(null!=fire && 
                    null!=mercs.Find(m => m.m_mercName.Contains(MercConst.迦顿男爵.m_name)) &&
                    null!=mercs.Find(m => m.m_mercName.Contains(MercConst.拉格纳罗斯.m_name)))
                {
                    m_mercList.Add(new MercCard(fire.ID, 0));
                    m_mercList.Add(new MercCard(MercConst.迦顿男爵.m_id, 0));
                    m_mercList.Add(new MercCard(MercConst.拉格纳罗斯.m_id, 0));
                }
            }
            else if ((m_mercList.Count+3) <= m_mercMax)
            {
                //冰队
                if(null!=mercs.Find(m => m.m_mercName.Contains(MercConst.瓦尔登_晨拥.m_name)) &&
                    null!=mercs.Find(m => m.m_mercName.Contains(MercConst.冰雪之王洛克霍拉.m_name)) &&
                    null!=mercs.Find(m => m.m_mercName.Contains(MercConst.吉安娜_普罗德摩尔.m_name)))
                {
                    m_mercList.Add(new MercCard(MercConst.瓦尔登_晨拥.m_id, 0));
                    m_mercList.Add(new MercCard(MercConst.冰雪之王洛克霍拉.m_id, 0));
                    m_mercList.Add(new MercCard(MercConst.吉安娜_普罗德摩尔.m_id, 0));
                }
            }

            //其他队伍
            //...
            */
        }

        public List<BattleTarget> GetBattleTargets(
            int turn,
            List<MercCard> targets_opposite_all,
            List<MercCard> targets_friendly_all,
            List<MercCard> targets_opposite_graveyrad)
            /*
            List<MercCard> mercenaries,
            List<MercCard> targets_opposite,
            List<MercCard> targets_friendly
            */
        {
            var battleTargetEntities = new List<BattleTarget>();
            var targets_opposite_valid = targets_opposite_all.FindAll(
                (MercCard t) => t.m_enable == true);
            var targets_friendly = targets_friendly_all.FindAll(
                (MercCard t) => t.m_enable == true);

            ////////// 火焰队 点火攻击血量最高的怪
            var fireUp = UtilsStra.FindMercenaryForName("安东尼", targets_friendly_all) ??
                            UtilsStra.FindMercenaryForName("赤精", targets_friendly_all) ??
                            UtilsStra.FindMercenaryForName("巴琳达", targets_friendly_all);
            var maxHealthTarget = UtilsStra.FindMaxHealthTarget(targets_opposite_valid);
            if (fireUp != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = maxHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("火球", fireUp)?.m_id ??
                               UtilsStra.FindSkillForName("烈焰之歌", fireUp)?.m_id ??
                               UtilsStra.FindSkillForName("烈焰之刺", fireUp)?.m_id ?? -1
                });
            }
            // 嘉顿
            var geddon = UtilsStra.FindMercenaryForName("迦顿", targets_friendly_all);
            if (geddon != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_skillId = UtilsStra.FindSkillForName("地狱火", geddon)?.m_id ?? -1
                });
            }
            // 螺丝
            var ragnaros = UtilsStra.FindMercenaryForName("拉格纳罗斯", targets_friendly_all);
            if (ragnaros != null)
            {
                if (fireUp != null)
                    battleTargetEntities.Add(new BattleTarget()
                    {
                        m_skillId = UtilsStra.FindSkillForName("死吧，虫子", ragnaros)?.m_id ?? -1
                    });
                else //打火机死了，螺丝点火
                    battleTargetEntities.Add(new BattleTarget()
                    {
                        m_skillId = UtilsStra.FindSkillForName("熔岩冲击", ragnaros)?.m_id ?? -1
                    });
            }
            // 如果有水元素，用水元素冻住速度最慢的敌人
            var water = UtilsStra.FindMercenaryForName("水元素", targets_friendly_all);
            if (water != null)
            {
                // 找到水元素的技能
                var attack = UtilsStra.FindSkillForName("攻击", water);

                // 找到最慢的敌人
                var slowestTarget = UtilsStra.FindSlowestTarget(targets_opposite_valid);

                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = slowestTarget?.m_id ?? -1,
                    m_skillId = attack?.m_id ?? -1
                });
            }

            ////////// 冰队 晨拥
            var Dawngrasp = UtilsStra.FindMercenaryForName("瓦尔登·晨拥", targets_friendly_all);
            if (Dawngrasp != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_skillId = UtilsStra.FindSkillForName("冰风暴", Dawngrasp)?.m_id ?? -1
                });
            }
            //雪王 
            var IceLord = UtilsStra.FindMercenaryForName("冰雪之王洛克霍拉", targets_friendly_all);
            if (IceLord != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_skillId = UtilsStra.FindSkillForName("冰雹", IceLord)?.m_id ?? -1
                });
            }
            //吉安娜
            var Jaina = UtilsStra.FindMercenaryForName("吉安娜·普罗德摩尔", targets_friendly_all);
            if (Jaina != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = maxHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("浮冰术", Jaina)?.m_id ?? -1
                });
            }

            ////////// 奥术队 龙心
            var Longxin = UtilsStra.FindMercenaryForName("珑心", targets_friendly_all);
            if (Longxin != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("天神之息", Longxin)?.m_id ?? -1
                });
            }
            //泰兰德·语风
            var Tyrande = UtilsStra.FindMercenaryForName("泰兰德·语风", targets_friendly_all);
            if (Tyrande != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_skillId = UtilsStra.FindSkillForName("奥术齐射", Tyrande)?.m_id ?? -1
                });
            }

            ////////// 海盗队 重拳先生
            var Smite = UtilsStra.FindMercenaryForName("重拳先生", targets_friendly_all);
            if (Smite != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("落水追击", Smite)?.m_id ?? -1
                });
            }
            //海盗帕奇斯
            var Patches = UtilsStra.FindMercenaryForName("海盗帕奇斯", targets_friendly_all);
            if (Patches != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("眼魔船长", Patches)?.m_id ?? -1
                });
            }

            //////////自然队 玛法里奥·怒风
            var Malfurion = UtilsStra.FindMercenaryForName("玛法里奥·怒风", targets_friendly_all);
            if (Malfurion != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("塞纳里奥波动", Malfurion)?.m_id ?? -1
                });
            }
            //古夫
            var Guff = UtilsStra.FindMercenaryForName("古夫·符文图腾", targets_friendly_all);
            if (Guff != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("活体荆棘", Guff)?.m_id ?? -1
                });
            }
            //布鲁坎
            var Brukan = UtilsStra.FindMercenaryForName("布鲁坎", targets_friendly_all);
            if (Brukan != null)
            {
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = maxHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("闪电链", Brukan)?.m_id ?? -1
                });
            }

            ////////// 龙队 奈法利安
            var Nefarian = UtilsStra.FindMercenaryForName("奈法利安", targets_friendly_all);
            if (Nefarian != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_opposite_valid);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("暗影烈焰", Nefarian)?.m_id ?? -1
                });
            }
            //希奈丝特拉
            var Sinestra = UtilsStra.FindMercenaryForName("希奈丝特拉", targets_friendly_all);
            if (Sinestra != null)
            {
                MercCard minHealthTarget = UtilsStra.FindMinHealthTarget(targets_friendly);
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_skillId = UtilsStra.FindSkillForName("暮光灭绝", Sinestra)?.m_id ?? -1
                });
                battleTargetEntities.Add(new BattleTarget()
                {
                    m_oppoTarId = minHealthTarget?.m_id ?? -1,
                    m_skillId = UtilsStra.FindSkillForName("法力壁垒", Sinestra)?.m_id ?? -1
                });
            }

            return battleTargetEntities;
        }
    }
}
